package dk.eclipse.android.badassapp.helper;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.widget.Toast;

/**
 * This helper class handles notifications and toasts.
 * 
 * @author Ronni Kahalani
 *
 */
public class NotificationHelper {

	/**
	 * Displays a toast.
	 * 
	 * @param context
	 * @param toastText
	 * @param toastDuration
	 */
	public  static void sendToast(Context context, String toastText, int toastDuration) {
		Toast toast = Toast.makeText(context, toastText,
				toastDuration);
		toast.show();
	}

	/**
	 * Sends a notification.
	 * 
	 * @param context
	 * @param notificationId
	 * @param toastText
	 * @param toastDuration
	 * @param icon
	 * @param tickerText
	 * @param when
	 * @param contentTitle
	 * @param contentText
	 * @param intentClass
	 * @param vibration
	 */
	public static void sendNotification(Context context, int notificationId, String toastText,
			int toastDuration, int icon, String tickerText, long when,
			String contentTitle, String contentText, long[] vibration) {

		sendToast(context, toastText, toastDuration);

		// Get a reference to the system notification manager service
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager notificationManager = (NotificationManager) context.getSystemService(ns);

		// Create a notification.
		Notification notification = new Notification(icon, tickerText, when);

		//Create a notification intent 
		Intent notificationIntent = new Intent(context, SmsManager.class);
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
				notificationIntent, 0);

		notification.setLatestEventInfo(context, contentTitle, contentText,
				contentIntent);
		notification.vibrate = vibration;

		notificationManager.notify(notificationId, notification);
	}

}
